package com.shujia.core.transformations

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object FlatMapOpt {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("filter算子操作")

    val sc = new SparkContext(conf)

    val lineRDD: RDD[String] = sc.textFile("spark/data/words.txt")

    /**
     *  flatMap算子，主要是对一个数组或其他序列类型的元素进行扁平化，一个序列只会执行一次
     */
    val wordsRDD: RDD[String] = lineRDD.flatMap((line: String) => {
      println("=============== 数加科技 =================")
      line.split(" ")
    })

    wordsRDD.foreach(println)

  }
}
